/*
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
	"common-cobra/pak"
	"fmt"

	"github.com/shirou/gopsutil/disk"
	"github.com/spf13/cobra"
)

// diskCmd represents the disk command
var diskCmd = &cobra.Command{
	Use:   "disk usage",
	Short: "command for diskusage  need none orone args",
	Long:  `查看磁盘使用情况，如果不带参数则查看所有磁盘使用情况，如果带路径则查看该路径使用情况;windows系统参数样例：C:`,
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			pak.GetAll()
		} else {
			usage, err := disk.Usage(args[0])
			if err != nil {
				fmt.Printf("Error getting disk usage\n")
				return
			}
			// 打印磁盘使用率信息
			fmt.Printf("Disk Usage of :\n")
			fmt.Printf("Total: %v GB\n", usage.Total/1024/1024/1024)
			fmt.Printf("Free: %v GB\n", usage.Free/1024/1024/1024)
			fmt.Printf("Used: %v GB\n", usage.Used/1024/1024/1024)
			fmt.Printf("Used Percent: %.2f%%\n", usage.UsedPercent)
		}
	},
}

func init() {
	rootCmd.AddCommand(diskCmd)
}
